package edu.guet.cn.gateway.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

/**
 * @Auther: hejianding
 * @Date: 2021/3/23 10:07
 * @Version: 1.0
 * @Inproduce: 路由的限流配置类
 */
@Configuration
public class RateLimiterConfig {
    /**
     * ip限流
     * @return
     */
    @Bean(value = "remoteAddrKeyResolver")
    public KeyResolver remoteAddrKeyResolver() {
        return exchange -> Mono.just(exchange.getRequest().getRemoteAddress().getAddress().getHostAddress());
    }

   /* *
     * 用户限流
     * @return
     */
/*
    @Bean
    KeyResolver userKeyResolver() {
        return exchange -> Mono.just(exchange.getRequest().getQueryParams().getFirst("userId"));
    }
*/

   /* *
     * 接口限流
     * @return
     */
  /*  @Bean
    KeyResolver apiKeyResolver() {
        return exchange -> Mono.just(exchange.getRequest().getPath().value());
    }*/
}
